<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet  [
  <!ENTITY nbsp   "&#160;">
  <!ENTITY copy   "&#169;">
  <!ENTITY reg    "&#174;">
  <!ENTITY trade  "&#8482;">
  <!ENTITY mdash  "&#8212;">
  <!ENTITY ldquo  "&#8220;">
  <!ENTITY rdquo  "&#8221;">
  <!ENTITY pound  "&#163;">
  <!ENTITY yen    "&#165;">
  <!ENTITY euro   "&#8364;">
]>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:php="http://php.net/xsl">
<xsl:template name="bee_ajaxGrid" match="/">
<xsl:variable name="grid" select="/form/widgets//*[id=/form/arrays/__request/value[@key='gridID']]"></xsl:variable>
  <div class="outerGridBorder1">
  <div class="outerGridBorder2">
  <div class="innerGridBorder">
  <!--<xsl:value-of select="/form/arrays/__request/value[@key='gridID']" />  -->
  <table cellspacing="0" width="100%">
	  <xsl:if test="$grid/caption != ''">
	    <caption>
	      <xsl:value-of select="$grid/caption" />
	    </caption>
	  </xsl:if>
    <tr>
	    <xsl:choose>
	      <xsl:when test="count($grid/columns/value) > 0">
			    <xsl:for-each select="$grid/columns/value">
			      <xsl:variable name="column" select="." />
			      <th class="columnCaption" width="25" scope="col" onclick='javascript:handleGridEvent({{ "__ajax":            "{/form/variables/__ajax}", 
			                                                                                              "sys_action":        "grid_set_order", 
			                                                                                              "grid_order_field":  "{$column/name}", 
			                                                                                              "grid_order":        "{/form/variables/grid_anti_order}", 
			                                                                                              "gridID":             "{$grid/id}" }})'>
			        <xsl:if test="$column/width">
			          <xsl:attribute name="width"><xsl:value-of select="$column/width" /></xsl:attribute>
			        </xsl:if>
			        <xsl:value-of select="$column/caption"/>
			        <xsl:if test="/form/variables/grid_order_field = $column/name">
			          <img><xsl:attribute name="src">/xslt/img/arrow<xsl:value-of select="substring(/form/variables/grid_order, 1, 3)"/>.gif</xsl:attribute></img>
			        </xsl:if>			      
			      </th>
			    </xsl:for-each>	
		    </xsl:when>  
		    <xsl:otherwise>
          <xsl:for-each select="$grid/DAORow/*[substring(name(), 1, 2) != '__']">
            <th class="columnCaption" width="25" scope="col" onclick='javascript:handleGridEvent({{ "__ajax":             "{/form/variables/__ajax}", 
                                                                                                    "sys_action":         "grid_set_order", 
                                                                                                    "grid_order_field":   "{name()}", 
                                                                                                    "grid_order":         "{/form/variables/grid_anti_order}", 
                                                                                                    "gridID":             "{$grid/id}" }})'><xsl:value-of select="name()"/>
              <xsl:if test="/form/variables/grid_order_field = name()">
                <img><xsl:attribute name="src">/xslt/img/arrow<xsl:value-of select="substring(/form/variables/grid_order, 1, 3)"/>.gif</xsl:attribute></img>
              </xsl:if>
            </th>
          </xsl:for-each> 		    
		    </xsl:otherwise>
      </xsl:choose>
      <th colspan="2" class="columnCaption">&nbsp;</th>
    </tr>
	  <xsl:for-each select="$grid/data/row">
	  <xsl:sort select="*[name(.)=/form/variables/grid_order_field]" order="{/form/variables/grid_order}" />
	    <xsl:variable name="stil">
	      <xsl:choose>
	        <xsl:when test="position() mod 2 = 0">par</xsl:when>
	        <xsl:otherwise>nepar</xsl:otherwise>
	      </xsl:choose>
	    </xsl:variable>
	    <xsl:variable name="row" select="." />
	    <tr class="{$stil}">
        <xsl:choose>
          <xsl:when test="count($grid/columns/value) > 0">
			      <xsl:for-each select="$grid/columns/value">
			        <xsl:variable name="columnName" select="name" />
			        <td><xsl:value-of select="$row/*[name()=$columnName]" /></td>
			      </xsl:for-each>
			      </xsl:when>
			      <xsl:otherwise>
			        <xsl:for-each select="$grid/DAORow/*[substring(name(), 1, 2) != '__']">
			        <xsl:variable name="columnName" select="name()" />
              <td><xsl:value-of select="$row/*[name()=$columnName]" /></td>
			        </xsl:for-each>
			      </xsl:otherwise>
			  </xsl:choose>
			      <xsl:if test="php:functionString('bee\bitwiseAND', $grid/showButtons, 1) = 1">
		          <td align="center" class="gumb" width="25px" onclick="location.href='index.php?__form={$grid/detailFormName}&amp;__frm_back={/form/variables/sys_page}&amp;{$grid/detailLinkField}={$row/*[name()=$grid/detailLinkField]}&amp;__noload=true'">edit</td>
			      </xsl:if>
			      <xsl:if test="php:functionString('bee\bitwiseAND', $grid/showButtons, 2) = 2">
		          <td align="center" class="gumb" width="25px" onclick="location.href='index.php?__form={$grid/detailFormName}&amp;__frm_back={/form/variables/sys_page}&amp;{$grid/detailLinkField}={$row/*[name()=$grid/detailLinkField]}&amp;__noload=true&amp;sys_action=delete'">delete</td>
			      </xsl:if>
			    </tr>
			  </xsl:for-each>
	  <tr>
	    <td>&nbsp;</td>
	    <td>&nbsp;</td>
	  </tr>
    <tr>
      <td class="pager">
      <xsl:attribute name="colspan">
        <xsl:choose>
          <xsl:when test="count($grid/columns/value) > 0">
            <xsl:value-of select="count($grid/columns/value) + 2"/>
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="count($grid/DAORow/*[substring(name(), 1, 2) != '__']) + 2"/>
          </xsl:otherwise>
        </xsl:choose>      
      </xsl:attribute>
      <table width="100%">
       <tr>
       <xsl:if test="$grid/num_rows &gt; $grid/grid_step">
        <td>
        <table><tr>
          <xsl:if test="$grid/page_no &gt; $grid/ffwd_step"><td style="border:dotted #999 thin; cursor:pointer" onclick='javascript:handleGridEvent({{ "__ajax": "{form/variables/__ajax}", "sys_action": "grid_first", "gridID":"{$grid/id}" }}) '>&lt;&lt;&lt;</td></xsl:if>
          <xsl:if test="$grid/page_no &gt;= $grid/ffwd_step"><td style="border:dotted #999 thin; cursor:pointer" onclick='javascript:handleGridEvent({{ "__ajax": "{form/variables/__ajax}", "sys_action": "grid_FBWD", "gridID":"{$grid/id}" }}) '>&lt;&lt;</td></xsl:if>
          <xsl:if test="$grid/page_no &gt; 0"><td style="border:dotted #999 thin; cursor:pointer" onclick='javascript:handleGridEvent({{ "__ajax": "{form/variables/__ajax}", "sys_action": "grid_prev", "gridID":"{$grid/id}" }}) '>&lt;</td></xsl:if>&nbsp;
          <xsl:if test="$grid/page_no &gt; 3"><td style="border:dotted #999 thin; cursor:pointer" onclick='javascript:handleGridEvent({{ "__ajax": "{form/variables/__ajax}", "sys_action": "grid_goto", "page_no": "{$grid/page_no - 4}", "gridID":"{$grid/id}" }}) '><xsl:value-of select="$grid/page_no - 3" /></td></xsl:if>
          <xsl:if test="$grid/page_no &gt; 2"><td style="border:dotted #999 thin; cursor:pointer" onclick='javascript:handleGridEvent({{ "__ajax": "{form/variables/__ajax}", "sys_action": "grid_goto", "page_no": "{$grid/page_no - 3}", "gridID":"{$grid/id}" }}) '><xsl:value-of select="$grid/page_no - 2" /></td></xsl:if>
          <xsl:if test="$grid/page_no &gt; 1"><td style="border:dotted #999 thin; cursor:pointer" onclick='javascript:handleGridEvent({{ "__ajax": "{form/variables/__ajax}", "sys_action": "grid_goto", "page_no": "{$grid/page_no - 2}", "gridID":"{$grid/id}" }}) '><xsl:value-of select="$grid/page_no - 1" /></td></xsl:if>
          <xsl:if test="$grid/page_no &gt; 0" ><td style="border:dotted #999 thin; cursor:pointer" onclick='javascript:handleGridEvent({{ "__ajax": "{form/variables/__ajax}", "sys_action": "grid_goto", "page_no": "{$grid/page_no - 1}", "gridID":"{$grid/id}" }}) '><xsl:value-of select="$grid/page_no" /></td></xsl:if><td>
          <xsl:value-of select="$grid/page_no + 1" /></td>
          <xsl:if test="$grid/page_no &lt; $grid/num_rows div $grid/grid_step - 1"><td style="border:dotted #999 thin; cursor:pointer" onclick='javascript:handleGridEvent({{ "__ajax": "{form/variables/__ajax}", "sys_action": "grid_goto", "page_no": "{$grid/page_no + 1}", "gridID":"{$grid/id}" }}) '><xsl:value-of select="$grid/page_no + 2" /></td></xsl:if>
          <xsl:if test="$grid/page_no &lt; $grid/num_rows div $grid/grid_step - 2"><td style="border:dotted #999 thin; cursor:pointer" onclick='javascript:handleGridEvent({{ "__ajax": "{form/variables/__ajax}", "sys_action": "grid_goto", "page_no": "{$grid/page_no + 2}", "gridID":"{$grid/id}" }}) '><xsl:value-of select="$grid/page_no + 3" /></td></xsl:if>
          <xsl:if test="$grid/page_no &lt; $grid/num_rows div $grid/grid_step - 3"><td style="border:dotted #999 thin; cursor:pointer" onclick='javascript:handleGridEvent({{ "__ajax": "{form/variables/__ajax}", "sys_action": "grid_goto", "page_no": "{$grid/page_no + 3}", "gridID":"{$grid/id}" }}) '><xsl:value-of select="$grid/page_no + 4" /></td></xsl:if>
          <xsl:if test="$grid/page_no &lt; $grid/num_rows div $grid/grid_step - 4"><td style="border:dotted #999 thin; cursor:pointer" onclick='javascript:handleGridEvent({{ "__ajax": "{form/variables/__ajax}", "sys_action": "grid_goto", "page_no": "{$grid/page_no + 4}", "gridID":"{$grid/id}" }}) '><xsl:value-of select="$grid/page_no + 5" /></td></xsl:if>
          <xsl:if test="$grid/page_no &lt; $grid/num_rows div $grid/grid_step - 1"><td style="border:dotted #999 thin; cursor:pointer" onclick='javascript:handleGridEvent({{ "__ajax": "{form/variables/__ajax}", "sys_action": "grid_next", "gridID":"{$grid/id}" }}) '>&gt;</td></xsl:if>
          <xsl:if test="$grid/page_no &lt; $grid/num_rows div $grid/grid_step - $grid/ffwd_step"><td style="border:dotted #999 thin; cursor:pointer" onclick='javascript:handleGridEvent({{ "__ajax": "{form/variables/__ajax}", "sys_action": "grid_FFWD", "gridID":"{$grid/id}" }}) '>&gt;&gt;</td></xsl:if>
          <xsl:if test="$grid/page_no &lt; $grid/num_rows div $grid/grid_step - $grid/ffwd_step - 1"><td style="border:dotted #999 thin; cursor:pointer" onclick='javascript:handleGridEvent({{ "__ajax": "{form/variables/__ajax}", "sys_action": "grid_last", "gridID":"{$grid/id}" }}) '>&gt;&gt;&gt;</td></xsl:if>
        </tr></table>
        </td>      
       </xsl:if>
        <td class="inpRight">
          <xsl:choose>
            <xsl:when  test="$grid/num_rows &gt; ($grid/page_no + 1) * $grid/grid_step">
              <xsl:value-of select="$grid/page_no * $grid/grid_step + 1"/> - <xsl:value-of select="($grid/page_no + 1) * $grid/grid_step"/> of <xsl:value-of select="$grid/num_rows"/>
            </xsl:when>
            <xsl:otherwise>
              <xsl:value-of select="$grid/page_no * $grid/grid_step + 1"/> - <xsl:value-of select="$grid/num_rows"/> of <xsl:value-of select="$grid/num_rows"/>
            </xsl:otherwise>
          </xsl:choose>
        </td>
       </tr>
      </table>
      </td>
    </tr>
   </table>
  </div>
  </div>
  </div>
</xsl:template>
</xsl:stylesheet>